package com.axzhengxin.platform.afterloan.domain;

import cn.hutool.core.util.StrUtil;
import com.axzhengxin.platform.afterloan.service.impl.CommonWarningTaskServiceImpl;
import lombok.Data;

import java.util.Optional;

/**
 * RiskModelRegHistory
 * 预警模型注册历史
 *
 * @author jiangnan
 * @date 2021/3/22
 */
@Data
public class RiskModelRegHistory {

    /**
     * 主键
     */
    private Long id;

    /**
     * 企业名称
     */
    private String entName;

    /**
     * 统一社会信用代码
     */
    private String uniscid;

    /**
     * 客户ID
     */
    private String customerId;

    public static RiskModelRegHistory init(CommonWarningTaskServiceImpl.RiskModelRequest request) {
        RiskModelRegHistory history = new RiskModelRegHistory();
        Optional.ofNullable(request)
                .map(CommonWarningTaskServiceImpl.RiskModelRequest::getData)
                .flatMap(data -> data.stream().findFirst())
                .ifPresent(data -> {
                    history.setCustomerId(data.getRcrUserNo());
                    history.setEntName(data.getEntName());
                    history.setUniscid(data.getUniscid());
                });
        if (StrUtil.isBlank(history.getCustomerId())) {
            return null;
        } else {
            return history;
        }
    }

}
